[DX12] Add support for Samplers in DX12.#1331
Conversation
d082a3c to
0609be6
Compare
0609be6 to
273e4a5
Compare
273e4a5 to
909509e
Compare
14ea640 to
99062f2
Compare
| enum class RootParameterType : uint32_t { | ||
| DescriptorTable = 0, | ||
| SamplerTable, | ||
| Constant, | ||
| CBV, | ||
| SRV, | ||
| UAV, | ||
| }; | ||
|
|
||
| struct RoogtSignatureLayout { | ||
| RootParameterType ParameterType : 3; | ||
| uint32_t Count : 29; | ||
|
|
||
| RoogtSignatureLayout(RootParameterType ParameterType, uint32_t Count) | ||
| : ParameterType(ParameterType), Count(Count) {} | ||
| RoogtSignatureLayout() = delete; | ||
| }; | ||
|
|
There was a problem hiding this comment.
Could've probably been two PRs, but at least this way it doesn't only introduces new API but it also shows how it's used
8095bff to
3c20e02
Compare
| // Depth formats require DepthStencil usage; non-depth formats forbid it. | ||
| if (IsDepth && !IsDS) | ||
| return llvm::createStringError( | ||
| std::errc::invalid_argument, | ||
| "Depth format '%s' requires DepthStencil usage.", | ||
| getFormatName(Desc.Fmt).data()); |
There was a problem hiding this comment.
Out of scope / unrelated?
| Ranges.get()[RangeIdx].OffsetInDescriptorsFromTableStart = | ||
| SamplerDescriptorIdx; | ||
|
|
||
| assert(Binding.DescriptorCount == 1 && "Manon expected this to be 1."); |
| UAV, | ||
| }; | ||
|
|
||
| struct RoogtSignatureLayout { |
There was a problem hiding this comment.
I am groot (roogt?)
| struct RoogtSignatureLayout { | |
| struct RootSignatureLayout { |
MarijnS95
left a comment
There was a problem hiding this comment.
A few more, on top of the inline notes:
Texture.h— dropping the "depth format requires DepthStencil usage" check is unrelated to samplers, and the depth-as-SRV path it enables still isn't correct (typedD32_FLOATcan't back an SRV withoutTYPELESS; those tests stayXFAIL). Maybe split out.- Implicit fallback now hard-errors on shader-embedded inline descriptors / root constants when no explicit
RootParametersare given (previously bound each set as a table). No test hits it, but it's a behavior change. assert(... "Manon expected this to be 1.")silently caps sampler arrays at 1 — prefer a realcreateStringErrorstating the invariant.RoogtSignatureLayout(and the error stringRootParamters) is misspelled.
Cleared on inspection: SamplerCreateDesc brace-init order matches the struct, the filter/comparison/address enum mappings are correct, and the 256-cap SamplerAllocator matches the existing allocator pattern.
| @@ -0,0 +1,67 @@ | |||
| //===- Sampler.h - Offload API Texture ------------------------------------===// | |||
There was a problem hiding this comment.
| //===- Sampler.h - Offload API Texture ------------------------------------===// | |
| //===- Sampler.h - Offload API Sampler ------------------------------------===// |
| // | ||
| // | ||
| //===----------------------------------------------------------------------===// |
There was a problem hiding this comment.
| // | |
| // | |
| //===----------------------------------------------------------------------===// |
| // Sampler(Sampler &&) = delete; | ||
| Sampler &operator=(const Sampler &) = delete; | ||
| // Sampler &operator=(Sampler &&) = delete; |
There was a problem hiding this comment.
| // Sampler(Sampler &&) = delete; | |
| Sampler &operator=(const Sampler &) = delete; | |
| // Sampler &operator=(Sampler &&) = delete; | |
| Sampler &operator=(const Sampler &) = delete; |
| const ComPtr<ID3D12DescriptorHeap> &SamplerHeap) { | ||
| // Bind descriptors in descriptor tables. | ||
| if (!DescHeap) | ||
| if (!DescHeap && !SamplerHeap) |
There was a problem hiding this comment.
| if (!DescHeap && !SamplerHeap) | |
| if (!DescHeap || !SamplerHeap) |
Because both are unconditionally dereferenced afterwards.
| for (uint32_t Idx = 0u; Idx < P.Sets.size(); ++Idx) { | ||
| DXCB.CmdList->SetComputeRootDescriptorTable(Idx, Handle); | ||
| Handle.Offset(P.Sets[Idx].Resources.size(), Inc); | ||
| for (uint32_t I = 0, N = DXPipeline.Layout.size(); I < N; ++I) { |
There was a problem hiding this comment.
Claude thinks this loop can be deduplicated leaving only the graphics vs compute-specific calls on the API.
| case dx::RootParamKind::DescriptorTable: | ||
| // TODO(manon): Add support for descriptor tables containing samplers | ||
| DXCB.CmdList->SetComputeRootDescriptorTable(RootParamIndex++, Handle); | ||
| Handle.Offset(P.Sets[DescriptorTableIndex++].Resources.size(), Inc); | ||
| break; |
There was a problem hiding this comment.
Samplers live in a separate heap, so a DescriptorTable mixing a sampler with CBV/SRV/UAV resources binds the wrong heap and Handle.Offset() over-advances past the descriptors actually written (no SamplerTable case here either). Hard-error until it's supported (case needs braces for the local):
| case dx::RootParamKind::DescriptorTable: | |
| // TODO(manon): Add support for descriptor tables containing samplers | |
| DXCB.CmdList->SetComputeRootDescriptorTable(RootParamIndex++, Handle); | |
| Handle.Offset(P.Sets[DescriptorTableIndex++].Resources.size(), Inc); | |
| break; | |
| case dx::RootParamKind::DescriptorTable: { | |
| const DescriptorSet &Set = P.Sets[DescriptorTableIndex++]; | |
| // TODO(manon): Add support for descriptor tables containing samplers. | |
| for (const auto &R : Set.Resources) | |
| if (R.isSampler()) | |
| return llvm::createStringError( | |
| "Descriptor tables containing samplers are not yet " | |
| "supported with explicit RootParameters."); | |
| DXCB.CmdList->SetComputeRootDescriptorTable(RootParamIndex++, Handle); | |
| Handle.Offset(Set.Resources.size(), Inc); | |
| break; | |
| } |
| break; | ||
| case DescriptorKind::SAMPLER: | ||
| llvm_unreachable("Not implemented yet."); // Requires a separate heap | ||
| llvm_unreachable("Sampler should have been filtered out."); |
There was a problem hiding this comment.
I would think this is dead code because of the continue on line 1425
There was a problem hiding this comment.
Yes, which is why I put the unreachable statement there. I want all cases to be handled instead of relying on the default case label.
Adds support for samplers in DX12.
This change is a lot larger than you would expect from adding samplers.
This is because samplers need to live in a separate DescriptorHeap which cascaded into a couple of issues:
Adding this feature does allow more tests to succeed on DX12.